﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Batalha_Estelar
{
    public abstract class Starship : GameObject
    {

        #region Fields

        protected float Speed;

        protected double tempo_aux = 0;

        protected const double atrasoTiro = 0.2f;

        public Vector2 Orientacao { get; set; }

        public FieldController MyFieldController { get; set; }

        #endregion

        #region Construtores

        public Starship(BatalhaEstelar game, Vector2 posicao, Vector2 orientacao, Texture2D textura)
            : base(game)
        {
            Textura = textura;
            Posicao = posicao;
            Orientacao = orientacao;

            MyFieldController = new FieldController(game, this);
            Direcao = new Vector2(0.0f, 0.0f);
            Speed = 250.0f;
        }

        #endregion

        #region GameObject Methods

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Textura, Posicao, Color.White);
        }

        protected override void Dispose(bool disposing)
        {
            //nada por enquanto...
            return;
        }

        #endregion

        #region Nave Methods

        public void Atirar(GameTime gameTime, Vector2 posicaoNave)
        {
            double tempo = gameTime.TotalGameTime.TotalSeconds;
            
            if (tempo > tempo_aux)
            {
                posicaoNave.X += (this.Textura.Bounds.Width - 1) / 2;
                Missel missel = new Missel(this.MyGame, this, posicaoNave, Orientacao);
                MyGame.State.Add(missel);
                tempo_aux = gameTime.TotalGameTime.TotalSeconds + atrasoTiro;
            }
        }

        protected Vector2 CalcNewPosition(GameTime time)
        {
            var config = MyGame.Config;
            var gameSpeed = config.GameSpeed;
            var totalSeconds = (float)time.ElapsedGameTime.TotalSeconds;

            return Posicao + Direcao * Speed * gameSpeed * totalSeconds;
        }

        #endregion

    }
}
